import { createSlice, createAsyncThunk } from '@reduxjs/toolkit';
import { findById } from '../../services/order';

export const fetchItemInfo = createAsyncThunk('itemInfo/fetchItemInfo', async (id) => {
    let { data } = await findById(id);

    return data.itemInfo.itemInfo;
})

const itemInfoSlice = createSlice({
    name: "itemInfo",
    initialState: {
        itemInfoVisible: false,
        itemInfo: []
    },
    reducers: {
        setItemInfoVisible(state, action) {
            state.itemInfoVisible = action.payload;
        }
    },
    extraReducers(builder) {
        builder.addCase(fetchItemInfo.fulfilled, (state, action) => {
            state.itemInfo = action.payload;
        })
    }
});

export const { setItemInfoVisible } = itemInfoSlice.actions;
export default itemInfoSlice.reducer;